<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
        <div class="layui-form-item" id="area-picker">
            <label class="layui-form-label required">电影院地址</label>
            <div class="layui-input-inline" style="width: 200px;">
                <select name="province" id="province" class="province-selector" lay-filter="province-1" required>
                    <option value="">请选择省</option>
                </select>
            </div>
        <div class="layui-input-inline" style="width: 200px;">
            <select name="city" id="city" class="city-selector" lay-filter="city-1" required>
                <option value="">请选择市</option>
            </select>
        </div>
        <div class="layui-input-inline" style="width: 200px;">
            <select name="area" id="county" class="county-selector" lay-filter="county-1" required>
                <option value="">请选择区</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">电影院名</label>
        <div class="layui-input-block">
            <input type="text" name="name" id="name" lay-verify="required" lay-reqtext="电影名不能为空" placeholder="请输入电影名" value="" class="layui-input">
            <span style="color: red" id="error"></span>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>

<script>
    //配置插件目录
    layui.config({
        base: '../../js/mods/'
        , version: '1.0'
    });

    let cityCode,countyCode,provinceCode,data;
    //一般直接写在一个js文件中
    layui.use(['layer', 'form', 'layarea'], function () {
        var layer = layui.layer
            , form = layui.form
            , layarea = layui.layarea;

        layarea.render({
            elem: '#area-picker',
            change: function (res) {
                //选择结果
                console.log(res)
            }
        });
    });


    layui.use(['form'], function () {
        let form = layui.form,
            layer = layui.layer,
            $ = layui.$;
            //监听提交
            form.on('submit(saveBtn)', function (data) {
                if ($("#city").val()==""||$("#province").val()==""||$("#county").val()==""){
                    layer.msg("请选择所在地区");
                    return false;
                }
                layer.confirm('确认是否添加?',{
                    title: '新增电影院',
                    icon:'3'
                },function (index){
                    $.post("${path}/cinames/save",data.field,function (result){
                        if(result.code=="200"){
                            layer.msg('添加成功！', {icon:1, time: 2000},function (){
                                parent.location.reload();
                                // 关闭弹出层
                                layer.close(index);
                                let iframeIndex = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(iframeIndex);
                            });
                        }else {
                            layer.msg('添加失败！', {icon:2});
                        }
                    });
                })
                return false;
            });
    });

</script>
</body>
</html>